/*
 * Copyright (C) 2018 Logos Technology Ltd.
 */

package com.logos.common.source.network.interceptor;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * @author Young Ken
 */

public class DecorateHeaderInterceptor implements Interceptor {

    private Map<String, String> mHeaders = new HashMap<>();

    public DecorateHeaderInterceptor(Map<String, String> headers) {
        this.mHeaders = headers;
    }

    @Override
    public Response intercept(Chain chain) throws IOException {

        Request.Builder builder = chain.request().newBuilder();
        for (String key : mHeaders.keySet()) {
            if (mHeaders.get(key) != null) {
                builder.addHeader(key, mHeaders.get(key));
            }
        }
        Request request = builder.build();
        return chain.proceed(request);
    }
}
